package com.liuhe.collections.test1;

import java.util.*;

public class Test4 {
    //创建集合添加省和城市(可多个)
    public static void main(String[] args) {
        HashMap<String, ArrayList<String>> hm = new HashMap<>();
        //先创建城市集合再分别添加
        ArrayList<String> city1 = new ArrayList<>();
        ArrayList<String> city2 = new ArrayList<>();
        ArrayList<String> city3 = new ArrayList<>();
        Collections.addAll(city1, "a1", "a2", "a3");
        Collections.addAll(city2, "b1", "b2", "b3");
        Collections.addAll(city3, "c1", "c2", "c3");
        //将数据添加到HashMap集合中
        hm.put("a", city1);
        hm.put("b", city2);
        hm.put("c", city3);
        //进行遍历输出
        System.out.println(hm);
        Set<String> keys = hm.keySet();
        //创建StringJoiner

        for (String key : keys) {
            StringJoiner sj = new StringJoiner(",", "", "");
            ArrayList<String> strings = hm.get(key);
            for (String str : strings) {
                sj.add(str);
            }
            System.out.println(key + " = " + sj);
        }
    }
}
